<?php

require_once(dirname(dirname(dirname(__FILE__))).'/includes.php');
require_once('lib.php');
require_once(dirname(dirname(__FILE__))."/common.php");

if (!$USER->ident || $USER->ident == 0){
	error('You must be logged in to access this page.');
}

$method = required_param('method', PARAM_ALPHA);

switch ($method){
	case 'addcourse':
		//check that date and courseid sent
		$courseId = required_param('id', PARAM_INT);
		$courseDateD = required_param('dateday', PARAM_INT);
		$courseDateM = required_param('datemonth', PARAM_INT);
		$courseDateY = required_param('dateyear', PARAM_INT);
		if (trim($courseDateD) == '' || trim($courseDateM) == '' || trim($courseDateY) == ''){
			break;
		}
		$courseDate = mktime(0, 0, 0, $courseDateM, $courseDateD, $courseDateY);
		$response = addCourse($courseId,$courseDate);
		break;
	case 'removecourse':
		//check that courseid sent
		$usercourseId = required_param('cuid', PARAM_INT);
		$response = removeCourse($usercourseId);
		break;
	
}

// set header to be XML
header('Content-Type: text/xml;');
$str = '<?xml version="1.0" encoding="UTF-8"?>';
$str .= '<response>';
if ($response) {
	$str .= responseToXML($response);
}
$str .= '</response>';

echo $str;

?>